<template>
  <div class="allEdit">
      <!-- allEdit 批量修改信息  导入 -->
        <el-button type="primary" plain @click="importDialog=true" size="mini">批量更新客户信息</el-button>
          <!-- 弹窗 -->
        <el-dialog
        title="导入"
        :visible.sync="importDialog"
        width="780px"
        :before-close="handleClose"
        >
          <el-upload
            class="upload-demo"
            ref="upload"
            :headers='{Authorization:$store.state.user.token}'
            :action='importUrl'
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList"
            :on-success="handleSuccess"
            :on-error="handleError"
            :auto-upload="false"
          >
          <el-button slot="trigger" size="small" type="primary">选择要导入的文件</el-button>
          <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">确认上传</el-button>
          </el-upload>
        </el-dialog>
  </div>
  
</template>

<script>
export default {
    name:'allEdit',
    data() {
        return {
        // 上传路径
        importUrl: `/api/cb/flCustomerInfo/batchUpdate`,
            // 导入窗口开关
        importDialog: false,
        //   // 上传数据
        fileList: [],

        }
    },
  methods: {
    // 弹窗关闭
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(() => {
          done();
        }).catch(_ => {});
    },
    // 上传的方法
    submitUpload() {
      this.$refs.upload.submit();
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    
    handleSuccess(res,file,fileList){
      console.log(res,file,fileList,888);
      if (res.flag) {
        // 提醒
        this.$message({
          message:res.message,
          type:'success'
        })
        this.$emit('allEditHandleSuccess','导入成功')
      }else{ 
        this.$alert(res.message, "导入失败：", {
          confirmButtonText: "确定",
          callback: action => {
            this.$message({
              type: "warning",
              message: res.message
            });
          }
        });
      }
      // 清空数组
      this.fileList = []
      // 关闭窗口
      this.importDialog = false
    },
    handleError(res,file,fileList){
      console.log(res,file,fileList,'失败');  
    },
  }
}
</script>

<style>

</style>